var t = getApp();

Page({
    data: {
        coupon: [],
        isShowNoTest: !1,
        isLoadMore: !0,
        last_page: 0,
        page: 1,
        coupon_length: "",
        show: !1,
        is_publish: !1
    },
    onLoad: function(t) {},
    onReady: function() {},
    onShow: function() {
        this.getData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {},
    getData: function() {
        var a = this, e = t.getNetAddresss("plugin.store-cashier.frontend.store.center.coupon.index");
        e += "&page=1", t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    for (var o = 0; o < e.data.data.length; o++) e.data.data[o].edit_active = !1;
                    a.data.last_page || a.setData({
                        last_page: 0
                    }), a.setData({
                        is_publish: e.data.publish
                    }), e.data.data.length > 0 && a.setData({
                        isShowNoTest: !1,
                        isLoadMore: !0,
                        last_page: e.data.last_page,
                        coupon: e.data.data,
                        coupon_length: e.data.total,
                        is_publish: e.data.publish
                    }), e.data.data.length <= 0 && a.setData({
                        isShowNoTest: !0,
                        coupon_length: 0
                    });
                } else 0 === e.result && (e.data.url ? wx.navigateTo({
                    url: e.data.url
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var a = this;
        if (this.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.last_page)) {
            this.setData({
                page: this.data.page + 1
            });
            var e = t.getNetAddresss("plugin.store-cashier.frontend.store.center.coupon.index");
            e += "&page=" + this.data.page, t._getNetWork({
                url: e,
                success: function(t) {
                    var e = t.data;
                    if (1 == e.result) {
                        for (var o = 0; o < e.data.data.length; o++) e.data.data[o].edit_active = !1;
                        var i = a.data.coupon.concat(e.data.data);
                        a.setData({
                            coupon: i
                        });
                    } else a.setData({
                        page: a.data.page - 1,
                        isLoadMore: !1
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    moreEvent: function(t) {
        var a = t.target.dataset.index || t.currentTarget.dataset.index;
        if (0 == this.data.coupon[a].edit_active) {
            this.emptyEditActive();
            var e = this.data.coupon;
            e[a].edit_active = !0, this.setData({
                coupon: e
            });
        } else this.emptyEditActive();
    },
    emptyEditActive: function() {
        for (var t = 0; t < this.data.coupon.length; t++) {
            var a = this.data.coupon;
            a[t].edit_active = !1, this.setData({
                coupon: a
            });
        }
    },
    Toedit: function(t) {
        var a = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageB/member/commodity_coupon/commodityCoupon_edit/commodityCoupon_edit?id=" + a
        });
    },
    commodityDelete: function(t) {
        var a = t.target.dataset.index || t.currentTarget.dataset.index;
        this.setData({
            show: !0,
            index: a
        });
    },
    goToCouponEdit: function(t) {
        var a = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageB/member/commodity_coupon/commodityCoupon_edit/commodityCoupon_edit?id=" + a
        });
    },
    onCloseShow: function() {
        this.setData({
            show: !1
        });
    },
    confimCancel: function() {
        this.setData({
            show: !1
        }), wx.showToast({
            title: "已取消删除",
            icon: "none"
        });
    },
    confimCanfim: function() {
        var a = this, e = this.data.index, o = this.data.coupon[e].id;
        this.setData({
            show: !1
        });
        var i = {
            id: o
        }, n = t.getNetAddresss("plugin.store-cashier.frontend.store.center.coupon.destroy");
        t._postNetWork({
            url: n,
            data: i,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.getData(), wx.showToast({
                    title: "优惠券删除成功",
                    icon: "none"
                })) : 0 === e.result && e.data.url || wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    provide: function(t) {
        var a = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageB/member/commodity_coupon/CommodityCouponGive/CommodityCouponGive?id=" + a
        });
    }
});